#! /usr/bin/env python
# =========================================================================
# construct.py
# =========================================================================
import os
from mflowgen.components import Graph, Step


def construct():

    g = Graph()

    # -----------------------------------------------------------------------
    # Parameters
    # -----------------------------------------------------------------------

    adk_name = 'tsmc16'
    adk_view = 'view-standard'

    parameters = {
        'construct_path': __file__,
        'design_name': 'Tile_PE',
        'clock_period': 10.0,
        'adk': adk_name,
        'adk_view': adk_view,

        # Synthesis
        'flatten_effort': 3,
        'topographical': False,

        # RTL Generation
        'interconnect_only': True
    }

    # -----------------------------------------------------------------------
    # Create nodes
    # -----------------------------------------------------------------------

    this_dir = os.path.dirname(os.path.abspath(__file__))

    # ADK step

    g.set_adk(adk_name)
    adk = g.get_adk_step()

    # Custom steps

    rtl = Step(this_dir + '/../../common/rtl')
    constraints = Step(this_dir + '/../../Tile_PE/constraints')
    # Default steps

    info = Step('info', default=True)
    # constraints= Step('constraints', default=True)
    dc = Step('synopsys-dc-synthesis', default=True)

    # -----------------------------------------------------------------------
    # Graph -- Add nodes
    # -----------------------------------------------------------------------

    g.add_step(info)
    g.add_step(rtl)
    g.add_step(constraints)
    g.add_step(dc)

    # -----------------------------------------------------------------------
    # Graph -- Add edges
    # -----------------------------------------------------------------------

    # Connect by name

    g.connect_by_name(adk, dc)

    g.connect_by_name(rtl, dc)
    g.connect_by_name(constraints, dc)

    # -----------------------------------------------------------------------
    # Parameterize
    # -----------------------------------------------------------------------

    g.update_params(parameters)

    return g


if __name__ == '__main__':
    g = construct()
